package com.office.personalOffice.personalInfoQuery.service.impl;

import com.office.personalOffice.personalInfoQuery.model.TbStaff;
import com.office.personalOffice.personalInfoQuery.dao.IPersonalInfoQuery;
import com.office.personalOffice.personalInfoQuery.model.TbDept;
import com.office.personalOffice.personalInfoQuery.service.IPersonalInfoQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PersonalInfoQueryService implements IPersonalInfoQueryService {

    @Autowired
    private IPersonalInfoQuery personalInfoQuery;

    public IPersonalInfoQuery getPersonalInfoQuery() {
        return personalInfoQuery;
    }

    public void setPersonalInfoQuery(IPersonalInfoQuery personalInfoQuery) {
        this.personalInfoQuery = personalInfoQuery;
    }

    /**
     * 拿取指定的员工信息
     * @param tbStaff
     * @return
     */
    @Override
    public List<TbStaff> getStaffInfoByCondition(TbStaff tbStaff) {

        List<TbStaff> staffInfoByCondition = personalInfoQuery.getStaffInfoByCondition(tbStaff);
        for (TbStaff staff : staffInfoByCondition) {
            String flag = staff.getFlag();
            String[] split = flag.split(";");
            ArrayList<Integer> integers = new ArrayList<>();
            for (String s : split) {
                Integer valueOf = Integer.valueOf(s);
                integers.add(valueOf);
            }
            staff.setFlagList(integers);
        }
        return staffInfoByCondition;

    }

    /**
     * 拿取所有的部门信息
     * @return
     */
    @Override
    public List<TbDept> getAllDept() {
        return personalInfoQuery.getAllDept();
    }
}
